import { Module } from "vuex";

export default {
  namespaced: true,
  state: {
    todos: [] as TodoType[],
  },
  mutations: {
    initTodos(state, payload: TodoType[]) {
      state.todos = payload;
    },
    addTodo(state, payload: TodoType) {
      state.todos.push(payload);
    },
  },
  actions: {
    initTodos({commit}) {
        setTimeout(() => {
            commit('initTodos', [
                {
                    id: String(Math.random()),
                    name: 'vue3',
                    compledted: false
                }
            ])
        }, 500)
    }
  }
} as Module<TodosType, StateInter>;
